package common

import (
	"context"
	"git.mycaigou.com/gfyx/common/rpc_client"
	"git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/common/constants"
	commonPb "git.mycaigou.com/gfyx/micro-gfyx-api/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/common"
	"git.myscrm.cn/golang/stark/v4"
)

type DmpReportRepository struct {
}

func NewDmpReportRepository() DmpReportRepositoryIface {
	return &DmpReportRepository{}
}

func (d *DmpReportRepository) GetSsoLoginUrl(ctx context.Context, request *commonPb.DmpLoginUrlRequest) (*commonPb.DmpLoginUrlResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetClientConn-error: %+v, request: %+v", request, err)
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := commonPb.NewDmpReportServiceClient(conn)
	res, err := client.GetDmpLoginUrl(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetDmpLoginUrl-error: %+v, request: %+v", request, err)
		return nil, err
	}
	return res, nil
}
